home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / xdialog.exe / DEMO.PAS < prev    next >
Pascal/Delphi Source File  |  1991-07-08  |  4KB  |  168 lines

  1. {$X+}
  2.  
  3. { Program Demo                                                }
  4. {   Demo the X_Dialog unit                                    }
  5. {                                                             }
  6. { Donn Aiken, 71150,2011                                      }
  7. { May 17, 1991                                                }
  8.  
  9. { Small example program to show how to create what functions  }
  10. { as a dialog box that scrolls.                               }
  11. { Look at TMyListBox object to see how it's done.             }
  12. {                                                             }
  13. { Based somewhat upon the ListBox example without a scrollbar }
  14. { by Mike Savage, 71121,3137.
  15. {                                                                             }
  16.  
  17.  
  18. program Demo;
  19.  
  20. uses Objects, Drivers, Views, Menus, Dialogs, App, MsgBox, X_Dialog;
  21.  
  22. const
  23.   cmNewDialog = 102;
  24.  
  25. type
  26.   TMyApp = object(TApplication)
  27.     procedure HandleEvent(var Event: TEvent); virtual;
  28.     procedure InitMenuBar; virtual;
  29.     procedure InitStatusLine; virtual;
  30.     procedure NewDialog;
  31.   end;
  32.  
  33.   PMyMenuBar = ^TMyMenuBar;
  34.   TMyMenuBar = object (TMenuBar)
  35.     procedure GetEvent (var Event: TEvent); virtual;
  36.   end;
  37.  
  38. procedure TMyMenuBar.GetEvent (var Event: TEvent);
  39.  
  40. var
  41.   oe : TEvent;
  42.  
  43. begin
  44.   TMenuBar.GetEvent (Event);
  45.  
  46.   if (Event.What = evCommand) and (Event.Command = cmMenu) then
  47.     begin
  48.       oe.What    := evKeyDown;
  49.       oe.KeyCode := kbEnter;
  50.       PutEvent (oe);
  51.     end;
  52. end;
  53.  
  54. { TMyApp }
  55. procedure TMyApp.HandleEvent(var Event: TEvent);
  56. begin
  57.   TApplication.HandleEvent(Event);
  58.   case Event.What of
  59.     evCommand :
  60.       begin
  61.         case Event.Command of
  62.           cmNewDialog: NewDialog;
  63.         else
  64.           Exit;
  65.         end;
  66.         ClearEvent(Event);
  67.       end;
  68.   end;
  69. end;
  70.  
  71. procedure TMyApp.InitMenuBar;
  72. var R: TRect;
  73. begin
  74.   GetExtent(R);
  75.   R.B.Y := R.A.Y + 1;
  76.   MenuBar := New(PMyMenuBar, Init(R, NewMenu(
  77.     NewSubMenu('~L~istBox', hcNoContext, NewMenu(
  78.       NewItem('~D~ialog', 'F2', kbF2, cmNewDialog, hcNoContext,
  79.       NewLine(
  80.       NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoContext,
  81.       nil)))),
  82.     nil))));
  83. end;
  84.  
  85. procedure TMyApp.InitStatusLine;
  86. var R: TRect;
  87. begin
  88.   GetExtent(R);
  89.   R.A.Y := R.B.Y - 1;
  90.   StatusLine := New(PStatusLine, Init(R,
  91.     NewStatusDef(0, $FFFF,
  92.       NewStatusKey('', kbF10, cmMenu,
  93.       NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
  94.       nil)),
  95.     nil)
  96.   ));
  97. end;
  98.  
  99. procedure TMyApp.NewDialog;
  100. var
  101.   Dialog        : PDialog;
  102.   R             : TRect;
  103.   Control, Labl : PView;
  104.   SC            : PCollection;
  105.   PListBoxData  : PBoxData;
  106.   AScrollBar    : PScrollBar;
  107.  
  108. begin
  109.     { create collection, insert strings }
  110.  
  111.     SC := New(PCollection, Init(20, 5));
  112.     SC^.Insert(New (PStringO, Init('Borland')));
  113.     SC^.Insert(New (PStringO, Init('Turbo')));
  114.     SC^.Insert(New (PStringO, Init('Vision')));
  115.     SC^.Insert(New (PStringO, Init('Object')));
  116.     SC^.Insert(New (PStringO, Init('Oriented')));
  117.     SC^.Insert(New (PStringO, Init('Programming')));
  118.     SC^.Insert(New (PStringO, Init('is')));
  119.     SC^.Insert(New (PStringO, Init('really')));
  120.     SC^.Insert(New (PStringO, Init('quite')));
  121.     SC^.Insert(New (PStringO, Init('a')));
  122.     SC^.Insert(New (PStringO, Init('bit')));
  123.     SC^.Insert(New (PStringO, Init('of')));
  124.     SC^.Insert(New (PStringO, Init('fun!')));
  125.  
  126.   PListBoxData^.PList := SC;
  127.   FillChar (PListBoxData^.Sel, Sizeof(PListBoxData^.Sel), #0);
  128.  
  129.   { create the scroll bar }
  130.   R.Assign (35, 3, 36, 9);
  131.   AScrollBar := New(PScrollBar, Init(R));
  132.  
  133.   { create the dialog box }
  134.   R.Assign(10,2,48,15);
  135.   Dialog := New(PDialog, Init(R, 'Demo Dialog'));
  136.   with Dialog^ do
  137.   begin
  138.     R.Assign(3,3,35,9);
  139.     Control := New(PMyListBox, Init(R, '√', 1, AScrollBar));
  140.  
  141.     Insert (Control);
  142.     Insert (AScrollBar);
  143.     R.Assign(2,2,11,3);
  144.     Labl := New(PLabel, Init(R, '~L~istbox:', Control));
  145.     Insert(Labl);
  146.     R.Assign(3,10,13,12);
  147.     Insert(New(PButton, Init(R, '~O~k', cmOK, bfDefault)));
  148.     R.Assign(14,10,24,12);
  149.     Insert(New(PButton, Init(R, '~C~ancel', cmCancel, bfNormal)));
  150.  
  151.  
  152.     SetData(PListBoxData);
  153.   end;
  154.  
  155.   if (DeskTop^.ExecView(Dialog) = cmOk) then
  156.     Dialog^.GetData (PListBoxData);
  157.   Dispose(Dialog, Done);
  158. end;
  159.  
  160. var
  161.   MyApp: TMyApp;
  162.  
  163. begin
  164.   MyApp.Init;
  165.   MyApp.Run;
  166.   MyApp.Done;
  167. end.
  168.